<?php

if ( ! function_exists('translit'))
{
	function translit($str)
	{

	    $upper = Array(
        '#А#','#Б#','#В#','#Г#','#Д#','#Е#','#Ё#','#Ж#','#З#','#И#',
        '#Й#','#К#','#Л#','#М#','#Н#','#О#','#П#','#Р#','#С#','#Т#',
        '#У#','#Ф#','#Х#','#Ц#','#Ч#','#Ш#','#Щ#','#Ъ#','#Ы#','#Ь#',
        '#Э#','#Ю#','#Я#');

	    $lower = Array(
	        'а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п','р','с','т',
	        'у','ф','х','ц','ч','ш','щ','ъ','ы','ь','э','ю','я');

	    $str = preg_replace($upper,$lower,$str);

		$from = Array(
        '#а#','#б#','#в#','#г#','#д#','#е#','#ё#','#ж#','#з#','#и#',
        '#й#','#к#','#л#','#м#','#н#','#о#','#п#','#р#','#с#','#т#',
        '#у#','#ф#','#х#','#ц#','#ч#','#ш#','#щ#','#ъ#','#ы#','#ь#',
        '#э#','#ю#','#я#');

	    $to   = Array(
	        "a", "b", "v", "g", "d","e", "yo", "zh", "z", "i","j", "k", "l", "m", "n",
	         "o", "p", "r", "s", "t","u", "f", "h", "c", "ch",
	         "sh", "sh", "", "y", "","je", "ju", "ja");

	    $str = preg_replace($from,$to,$str);

	    $str = str_replace(' ','_',$str);
	    $str = str_replace('+','_',$str);
	    $str = str_replace('-','_',$str);

	    $str = preg_replace('[^0-9a-z_]mi','',$str);

	    $str = trim($str);

	    return $str;
	}
}

?>